package com.kakaxi.mybilibili.adapter;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.SparseBooleanArray;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.kakaxi.mybilibili.R;
import com.kakaxi.mybilibili.view.LinearMarginDecoration;

import java.util.List;

/**
 * Created by kakaxi on 16/11/16.
 */

public class LiveCategoryRoomsTagRecyAdapter extends BaseQuickAdapter<String, BaseViewHolder> {

    /** 布尔数组 **/
    private SparseBooleanArray mCheckedBooleanArray = new SparseBooleanArray();

    /** 间距 **/
    private int mMargin = 18;


    public LiveCategoryRoomsTagRecyAdapter(List<String> data) {
        super(R.layout.item_recy_live_category_rooms_tag, data);
    }


    @Override
    protected void convert(BaseViewHolder baseViewHolder, String s) {
        baseViewHolder
                .setText(R.id.chk_live_category_rooms_tag, s)
                .setChecked(R.id.chk_live_category_rooms_tag, mCheckedBooleanArray.get
                        (baseViewHolder.getAdapterPosition()));
    }


    @Override
    public void onAttachedToRecyclerView(RecyclerView recyclerView) {
        super.onAttachedToRecyclerView(recyclerView);
        if (recyclerView.getLayoutManager() == null) {
            LinearLayoutManager layoutManager = new LinearLayoutManager(recyclerView
                    .getContext(), LinearLayoutManager.HORIZONTAL, false);
            recyclerView.setLayoutManager(layoutManager);
        }
        LinearMarginDecoration linearMarginDecoration = new LinearMarginDecoration(recyclerView
                .getContext());
        linearMarginDecoration.setMargin(6, mMargin, 6, mMargin);
        recyclerView.addItemDecoration(linearMarginDecoration);
    }

    /** 设置标签选中布尔数据 **/
    public void setCheckedBooleanArray(SparseBooleanArray checkedBooleanArray) {
        mCheckedBooleanArray = checkedBooleanArray;
        notifyDataSetChanged();
    }

}
